/**
 * @name MapData
 * @author darcrand
 * @desc
 */

import { observable, action, configure } from 'mobx'
import { StoreModule } from '@/utils/mobx-store'
import { post } from '@/utils/axios'

configure({ enforceActions: true })

class MapData extends StoreModule {
    @observable
    markerList = []

    @action.bound
    async getMarkers({ lng = '113.5323', lat = '22.23588', radius = '500', type = '0', areaId = 'xxxxxx' } = {}) {
        try {
            const res = await post('/blockchain/showLocationParam', {
                centerLongitude: lng,
                centerLatitude: lat,
                radius,
                type,
                areaId
            })

            if (res.errorCode === '200') {
                this.setState({
                    markerList: res.data.locations.map(v => ({ ...v, hash: `${v.hash}-${Math.random().toString(32)}` }))
                })
            }
        } catch (err) {
            console.error('http:', err)
        }
    }

    @action.bound
    async getDetail(hash) {}
}

export default MapData
